<template>
	<view class="container">
		<view class="serch-top" :class="{animation:isAnimation}">
			<view class="cu-bar search">
				<view class="action">
					<text>广州</text>
					<text class="cuIcon-triangledownfill"></text>
				</view>
				<view class="search-form round">
					<text class="cuIcon-search"></text>
					<input @focus="InputFocus" @blur="InputBlur" :adjust-position="false" type="text" placeholder="搜索图片、文章、视频"
					 confirm-type="search"></input>
				</view>
				<view class="cu-avatar round" style="background-image:url(https://ossweb-img.qq.com/images/lol/web201310/skin/big11010.jpg;margin-right:8px;"></view>

			</view>
		</view>
		<view class="hiddenImg" v-show="isAnimation" :style="[{
			transform: coverTransform,
			transition: coverTransition
		}]">
			<image src="https://image.weilanwl.com/gif/loading-black.gif" mode="aspectFill"></image>
		</view>
		<view class="cover-container" :style="[{
			transform: coverTransform,
			transition: coverTransition
		}]"
		 @touchstart="coverTouchstart" @touchmove="coverTouchmove" @touchend="coverTouchend">
			<!-- 头部轮播 -->
			<view class="carousel-section">
				<swiper class="screen-swiper" indicator-color="#8799a3" indicator-active-color="#ffffff" :indicator-dots="true"
				 :circular="true" :autoplay="true" interval="5000" duration="500">
					<swiper-item v-for="(item,index) in swiperList" :key="index">
						<image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
						<video :src="item.url" autoplay loop muted :show-play-btn="false" :controls="false" objectFit="cover" v-if="item.type=='video'"></video>
					</swiper-item>
				</swiper>
			</view>
			<!-- 分类 -->
			<view class="cate-section">
				<view class="cate-item">
					<image src="/static/temp/c3.png"></image>
					<text>环球美食</text>
				</view>
				<view class="cate-item">
					<image src="/static/temp/c5.png"></image>
					<text>个护美妆</text>
				</view>
				<view class="cate-item">
					<image src="/static/temp/c6.png"></image>
					<text>营养保健</text>
				</view>
				<view class="cate-item">
					<image src="/static/temp/c7.png"></image>
					<text>家居厨卫</text>
				</view>
				<view class="cate-item">
					<image src="/static/temp/c8.png"></image>
					<text>速食生鲜</text>
				</view>
				<view class="cate-item">
					<image src="/static/temp/c3.png"></image>
					<text>环球美食</text>
				</view>
				<view class="cate-item">
					<image src="/static/temp/c5.png"></image>
					<text>个护美妆</text>
				</view>
				<view class="cate-item">
					<image src="/static/temp/c6.png"></image>
					<text>营养保健</text>
				</view>
			</view>

			<view class="ad-1">
				<image src="/static/images/ad1.jpg.png" mode="scaleToFill"></image>
			</view>

			<!-- 秒杀楼层 -->
			<view class="seckill-section">
				<view class="s-header">
					<text class="left-title">品牌专区</text>
					<text class="tip">8点场</text>
					<text class="hour timer">07</text>
					<text class="minute timer">13</text>
					<text class="second timer">55</text>
				</view>
				<scroll-view class="floor-list" scroll-x>
					<view class="scoll-wrapper">
						<view v-for="(item, index) in goodsList" :key="index" class="floor-item" @click="navToDetailPage(item)">
							<image :src="item.image" mode="aspectFill"></image>
							<view class="floor-item-cn2">
								<text class="price">￥{{item.price}}</text>
								<text class="title clamp">{{item.title}}</text>
							</view>

						</view>
						<view class="more">
							<text>查看全部</text>
							<text>More+</text>
						</view>
					</view>
				</scroll-view>
			</view>
			<!-- 推荐门店 -->
			<view class="left-title m-au">推荐门店</view>
			<view class="seckill-section seckill-section2">
				<view class="seckill-section-list" v-for="(item,m) in todayList" :key="m" @click=navToStore(item)>
					<view class="s-store-img">
						<image class="s-line-img-cn" :src="item.resourcesUrl"></image>
					</view>
					<view class="s-store-right">
						<view class="s-store-text clamp">{{item.title}}</view>
						<view class="s-store-two">
							<uni-rate disabled="true" :value="item.avgGrade" size="12" activeColor="#a189f9"></uni-rate>
							<text class="s-store-two-title">{{item.num}}</text>
						</view>
						<view class="s-store-three">
							<view class="s-store-trait" v-for="(item1,trait) in item.infrNameList" :key="trait">
								<text class="s-store-trait-cn">{{item1}}</text>
							</view>
						</view>
						<view class="s-store-distance">
							<view class="s-store-address clamp">{{item.areaName}}</view>
							<view class="s-store-range">{{item.distanceStr}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	import uniRate from "@/components/uni-rate/uni-rate.vue";
	export default {
		components: {
			uniRate
		},
		data() {
			return {
				todayList: [{
						resourcesUrl: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg',
						title: '美发沙龙旗舰店（青浦旗舰店)',
						avgGrade: '4',
						num: 1003,
						infrNameList: ['价格实惠', '服务号', '价格公道'],
						areaName: '上海市青浦区华新镇新风中路33号',
						distanceStr: '1.3km'
					},
					{
						resourcesUrl: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg',
						title: '美发沙龙旗舰店（青浦旗舰店)',
						avgGrade: '4',
						num: 1003,
						infrNameList: ['价格实惠', '服务号', '价格公道'],
						areaName: '上海市青浦区华新镇新风中路33号',
						distanceStr: '1.3km'
					},
					{
						resourcesUrl: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg',
						title: '美发沙龙旗舰店（青浦旗舰店)',
						avgGrade: '4',
						num: 1003,
						infrNameList: ['价格实惠', '服务号', '价格公道'],
						areaName: '上海市青浦区华新镇新风中路33号',
						distanceStr: '1.3km'
					},
					{
						resourcesUrl: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg',
						title: '美发沙龙旗舰店（青浦旗舰店)',
						avgGrade: '4',
						num: 1003,
						infrNameList: ['价格实惠', '服务号', '价格公道'],
						areaName: '上海市青浦区华新镇新风中路33号',
						distanceStr: '1.3km'
					}
				],
				swiperList: [{
					id: 0,
					type: 'image',
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg'
				}, {
					id: 1,
					type: 'image',
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big37006.jpg',
				}, {
					id: 2,
					type: 'image',
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg'
				}, {
					id: 3,
					type: 'image',
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
				}, {
					id: 4,
					type: 'image',
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big25011.jpg'
				}, {
					id: 5,
					type: 'image',
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21016.jpg'
				}, {
					id: 6,
					type: 'image',
					url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big99008.jpg'
				}],
				isAnimation: false,
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
				goodsList: []
			};
		},

		onLoad() {
			this.loadData();
		},
		methods: {
			//详情页
			navToStore() {

			},
			async loadData() {
				let goodsList = await this.$api.json('goodsList');
				this.goodsList = goodsList || [];
			},
			//详情页
			navToDetailPage(item) {
				//测试数据没有写id，用title代替
				let id = item.title;
				uni.navigateTo({
					url: `/pages/product/product?id=${id}`
				})
			},
			//下拉开始
			coverTouchstart(e) {
				if (pageAtTop === false) {
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;

			},
			//下拉中
			coverTouchmove(e) {
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if (moveDistance < 0) {
					this.moving = false;
					this.isAnimation = false;
					return;
				}
				this.isAnimation = true;
				this.moving = true;
				if (moveDistance >= 80 && moveDistance < 100) {
					moveDistance = 80;
				}

				if (moveDistance > 0 && moveDistance <= 80) {
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			//下拉结束
			coverTouchend() {
				if (this.moving === false) {
					return;
				}
				this.isAnimation = false;
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			}
		}

	}
</script>

<style lang="scss">
	.m-au {
		margin: 0 22rpx;
	}

	.left-title {
		color: #333333;
		font-size: 40rpx;
		font-weight: bold;
		letter-spacing: 8rpx;
	}

	.cover-container {
		background-image: linear-gradient(#f9f9f9, #f1f1f1);
	}

	.serch-top {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		background-image: linear-gradient(45deg, #8F8CFF, #A389F8);
		color: #666666;
		z-index: 2;
	}

	.animation {
		animation: mymove 2s;
		animation-fill-mode: forwards;
	}

	.hiddenImg {
		position: fixed;
		top: -80px;
		left: 0;
		width: 100%;
		height: 130px;
	}

	.hiddenImg image {
		width: 100%;
		height: 100%;
	}

	/* #ifdef MP */
	.mp-search-box {
		position: absolute;
		left: 0;
		top: 30upx;
		z-index: 9999;
		width: 100%;
		padding: 0 80upx;

		.ser-input {
			flex: 1;
			height: 56upx;
			line-height: 56upx;
			text-align: center;
			font-size: 28upx;
			color: $font-color-base;
			border-radius: 20px;
			background: rgba(255, 255, 255, .6);
		}
	}

	page {
		.cate-section {
			position: relative;
			z-index: 5;
			border-radius: 16upx 16upx 0 0;
			margin-top: -20upx;
		}

		.carousel-section {
			padding: 0;

			.titleNview-placing {
				padding-top: 0;
				height: 0;
			}

			.carousel {
				.carousel-item {
					padding: 0;
				}
			}

			.swiper-dots {
				left: 45upx;
				bottom: 40upx;
			}
		}
	}

	/* #endif */


	page {
		background: #f5f5f5;
	}

	.m-t {
		margin-top: 16upx;
	}

	/* 头部 轮播图 */
	.carousel-section {
		position: relative;
		margin-top: 50px;
	}

	.carousel {
		width: 100%;
		height: 410rpx;

		.carousel-item {
			width: 100%;
			height: 100%;
			padding: 0 28upx;
			overflow: hidden;
		}

		image {
			width: 100%;
			height: 100%;
			border-radius: 10upx;
		}
	}

	.swiper-dots {
		display: flex;
		position: absolute;
		left: 60upx;
		bottom: 15upx;
		width: 72upx;
		height: 36upx;
		background-image: url();
		background-size: 100% 100%;

		.num {
			width: 36upx;
			height: 36upx;
			border-radius: 50px;
			font-size: 24upx;
			color: #fff;
			text-align: center;
			line-height: 36upx;
		}

		.sign {
			position: absolute;
			top: 0;
			left: 50%;
			line-height: 36upx;
			font-size: 12upx;
			color: #fff;
			transform: translateX(-50%);
		}
	}

	/* 分类 */
	.cate-section {
		display: flex;
		justify-content: space-around;
		align-items: center;
		flex-wrap: wrap;
		padding: 0 16rpx 30rpx 16rpx;

		.cate-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			font-size: $font-sm + 2upx;
			color: $font-color-dark;
			margin-top: 30rpx;
			width: 25%;
		}

		/* 原图标颜色太深,不想改图了,所以加了透明度 */
		image {
			width: 88upx;
			height: 88upx;
			margin-bottom: 14upx;
			border-radius: 50%;
			opacity: .7;
			box-shadow: 4upx 4upx 20upx rgba(250, 67, 106, 0.3);
		}
	}

	.ad-1 {
		width: 100%;
		height: 210upx;
		padding: 10upx 16rpx;


		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	/* 秒杀专区 */
	.seckill-section {
		margin: 4rpx 16rpx 24rpx;
		background: #fff;
		padding: 0 20rpx;
		border-radius: 20rpx;

		.s-header {
			display: flex;
			align-items: center;
			height: 92upx;
			line-height: 1;

			.s-img {
				width: 140upx;
				height: 30upx;
			}

			.tip {
				font-size: $font-base;
				color: $font-color-light;
				margin: 0 20upx 0 40upx;
			}

			.timer {
				display: inline-block;
				width: 40upx;
				height: 36upx;
				text-align: center;
				line-height: 36upx;
				margin-right: 14upx;
				font-size: $font-sm+2upx;
				color: #fff;
				border-radius: 2px;
				background: rgba(0, 0, 0, .8);
			}

			.icon-you {
				font-size: $font-lg;
				color: $font-color-light;
				flex: 1;
				text-align: right;
			}
		}

		.floor-list {
			white-space: nowrap;
		}

		.scoll-wrapper {
			display: flex;
			align-items: flex-start;
		}

		.floor-item {
			width: 206rpx;
			margin-right: 20upx;
			font-size: $font-sm;
			color: $font-color-dark;
			line-height: 1.8;

			image {
				width: 206rpx;
				height: 122rpx;
				border-radius: 6upx;
			}

			.title {
				font-size: $font-sm - 6upx;
				color: #999999;
			}

			.price {
				color: #F44022;
			}

			.floor-item-cn2 {
				display: flex;
				justify-content: space-between;
			}
		}

		.more {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			flex-shrink: 0;
			width: 180upx;
			height: 180upx;
			border-radius: 6upx;
			background: #f3f3f3;
			font-size: $font-base;
			color: $font-color-light;

			text:first-child {
				margin-bottom: 4upx;
			}
		}
	}

	// 推荐门店
	.seckill-section2{
		padding: 0;
		background: inherit;
	}
	.seckill-section-list {
		display: flex;
		flex-direction: row;
		padding: 20rpx 20rpx 20rpx 20rpx;
		justify-content: space-between;
		background: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
		.s-store-img {
			width: 272rpx;
			height: 208rpx;
			overflow: hidden;

		}

		.s-line-img-cn {
			width: 100%;
			height: 100%;
		}

		.s-store-right {
			display: flex;
			flex-direction: column;
			font-size: 28rpx;
			margin-left: 10rpx;
			width: 400rpx;
			overflow: hidden;
			justify-content: space-evenly;
		}
		.s-store-text {
			font-size: 34rpx;
			color: #333333;
			font-size: 17px;
			font-weight: 600;
		}
		.s-store-two{
			display: flex;
			align-items: center;
		}
		.s-store-distance {
			position: relative;
			display: flex;
			justify-content: space-between;
		}
		.s-store-three {
			display: flex;
			flex-direction: row;
			align-items: center;
			overflow: hidden;
			color: #333333;
			font-size: 24rpx;
		}

		.s-store-trait {
			box-sizing: content-box;
			height: 36rpx;
			border: 1rpx solid #D9D9D9;
			border-radius: 10px;
			font-size: 20rpx;
			margin-right: 10rpx;
			color: #818181;
			line-height: 34rpx;
			padding: 0 4px;
		}

		.s-store-trait:nth-child(3n+0) {
			margin-right: 0px;
		}
	}

	@keyframes mymove {
		0% {
			opacity: 1
		}

		100% {
			opacity: 0
		}
	}

	/* .carMrg {
		margin-top: 0;
	} */
</style>
